<?php
class CdeModule extends AppModel {

	var $name = 'CdeModule';

	//The Associations below have been created with all possible keys, those that are not needed can be removed
	var $belongsTo = array(
		'CdeUnit' => array(
			'className' => 'CdeUnit',
			'foreignKey' => 'cde_unit_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);

	var $hasMany = array(
		'CdeAnswer' => array(
			'className' => 'CdeAnswer',
			'foreignKey' => 'cde_module_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		),
		'CdeReferencelink' => array(
			'className' => 'CdeReferencelink',
			'foreignKey' => 'cde_module_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		)
	);
	function getContinueModule($completedmoduleid=null,$unitid=null,$userrole=null) {
		if ($userrole=='admin') {
			$tempt=$this->query('SELECT id FROM cde_modules where cde_unit_id='.$unitid.' and id > '.$completedmoduleid.' order by id ASC limit 1');
		}else {
			$tempt=$this->query('SELECT id FROM cde_modules where cde_unit_id='.$unitid.' and id > '.$completedmoduleid.' and enabled=1 order by id ASC limit 1');
		}
		return $tempt;
	}
}
?>